package com.gxa.saas.admin.service.impl;

import com.gxa.saas.admin.mapper.BannerMapper;
import com.gxa.saas.admin.mapper.UserMapper;
import com.gxa.saas.admin.service.BannerService;
import com.gxa.saas.core.entity.vo.BannerVO;
import com.gxa.saas.core.entity.vo.CommodityVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @Author cowboy
 * @Date 2022/7/27 10:51
 * @Version 1.0
 */
@Service
public class BannerServiceImpl implements BannerService {

    @Resource
    private BannerMapper bannerMapper;

    @Override
    public BannerVO QueryBanner() {
        return this.bannerMapper.QueryBanner();
    }

    @Override
    public BannerVO QueryBannerByCondition(String name) {
        return this.bannerMapper.QueryBannerByCondition(name);
    }

    @Override
    public void InsertBanner(BannerVO bannerVO) {
        LocalDateTime date = LocalDateTime.now();
        bannerVO.setCreationTime(date);
        this.bannerMapper.InsertBanner(bannerVO);
    }

    @Override
    public void OperationBanner(BannerVO bannerVO) {
        this.bannerMapper.OperationBanner(bannerVO);
    }

    @Override
    public void DeleteBanner(Integer id) {
        this.bannerMapper.DeleteBanner(id);
    }

    @Override
    public List<CommodityVO> QueryProduct() {
        List<CommodityVO> commodityVO = this.bannerMapper.QueryProduct();
        for (int i = 0; i < commodityVO.size(); i++) {
            commodityVO.get(i).setPicture(this.bannerMapper.QueryPic(commodityVO.get(i).getId()));
        }
        return commodityVO;
    }

    @Override
    public List<CommodityVO> QueryProductByName(String name) {
        List<CommodityVO> commodityVO = this.bannerMapper.QueryProductByName(name);
        for (int i = 0; i < commodityVO.size(); i++) {
            commodityVO.get(i).setPicture(this.bannerMapper.QueryPic(commodityVO.get(i).getId()));
        }
        return commodityVO;
    }

    @Override
    public void DeleteProduct(Integer id) {
        this.bannerMapper.DeleteProduct(id);
    }
}
